const router = require('koa-router')()
const { loginRedirect, loginCheck } = require('../middlewares/loginChecks')

router.get('/', loginRedirect, async (ctx, next) => {
  // await ctx.render('index', {
  //   title: 'Hello Koa 2!',
  //   msg: 'heolloo',
  //   isMe: false,
  //   blogList:[
  //     {
  //       id: 1,
  //       title: 'aaa'
  //     },
  //     {
  //       id: 2,
  //       title: 'bbb'
  //     },
  //     {
  //       id: 3,
  //       title: 'ccc'
  //     }
  //   ]
  // })
  await ctx.render('index', {
    userData: {
      userInfo: '',
      fansData: {
        count: '',
        list: []
      },
      followersData: {
        count: '',
        list: []
      },
      atCount:''
    },
    blogData: {
      isEmpty:'',
      blogList:[],
      pageSize:'',
      pageIndex:'',
      count:''
    }
  })
})

router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string'
})

router.get('/json', loginCheck, async (ctx, next) => {
  // 使用 session
  const session = ctx.session
  if(session.viewNum == null){
    session.viewNum = 0
  }
  session.viewNum ++
  ctx.body = {
    title: 'koa2 json'
    // title: 'koa2 json',
    // asd: 'koa2 json',
    // viewNum: session.viewNum
  }
})

router.get('/profile/:userName', async(ctx, next) => {
  const {userName} = ctx.params
  ctx.body = {
    title: 'this is  profile',
    userName
  }
})

router.get('/loadMore/:userName/:page', async(ctx, next) => {
  const {userName, page} = ctx.params
  ctx.body = {
    title: 'this is  profile',
    userName,
    page
  }
})

module.exports = router
